package com.car.util;

import java.net.InetAddress;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jsoup.nodes.Document;

public class Util {

	// 给定字符串和正则表达式，判断是否匹配
	public static boolean isMatched(String str, String regex) {
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(str);
		// System.out.println(matcher);
		return matcher.matches();
	}

	// 给定字符串和正则表达式，获得匹配的字�?
	public static Matcher getMatched(String str, String regex) {
		Matcher match = null;
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(str);
		if (matcher.find()) {
			match = matcher;
		}
		return match;

	}

	// 获得格式化的时间
	public static Date getDate(String date) {
		Date time = null;
		String s1 = date.replace("年", "-");
		String s2 = s1.replace("月", "-");
		String s3 = s2.replace("日", "");
		try {
			DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			time = format.parse(s3);
		} catch (ParseException e) {
			DateFormat format = new SimpleDateFormat("yyyy-MM");
			try {
				time = format.parse(s3);
			} catch (ParseException e1) {
				e1.printStackTrace();
			}
		}

		java.sql.Date sqlDate = new java.sql.Date(time.getTime());
		return sqlDate;
	}

	public static String getStandDate(String s) {
		String s1 = s.replace("年", "-");
		String s2 = s1.replace("月", "-");
		String s3 = s2.replace("日", "");
		return s3;

	}

	// 将抓取的表情符号过滤掉
	public static String deleteChar(String data) {
		byte[] b = data.getBytes();
		byte[] by = new byte[b.length];
		for (int i = 0; i < b.length;) {
			if (b[i] == -16) {
				i += 4;
			} else {
				by[i] = b[i];
				i++;
			}
		}

		return new String(by);
	}

	public static void main(String[] args) {
		System.out.println(Util.deleteChar("Jsoup获取全国地区数据属性值（省市县镇村）"));
	}

}
